package com.weicai.hive.udf;

import com.weicai.caesar.CaesarUtil;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;


public class CaesarEncodeUDF extends UDF {

    public Text evaluate(String str, int force) {
        if (str == null || str.isEmpty()) {
            return null;
        }
        Text text = new Text("");
        String val = str;
        if (force == 1 || !CaesarUtil.isEncrypted(str)) {
            val = CaesarUtil.encode(str);
        }
        text.set(val);
        return text;
    }

    public Text evaluate(String str) {
        return evaluate(str, 0);
    }

    public static void main(String[] args) {
        Text a = new CaesarEncodeUDF().evaluate("13131313");
        System.out.println(a);
    }
}